package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.jieshi.config.JieShiConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.jieshi.JieShiMgr;

import java.util.ArrayList;
import java.util.List;

public class JieShiRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        JieShiConfig config = JieShiMgr.getConfig();
        if (config == null) {
            return;
        }
        ActivityInfo activityInfo = config.getActivityInfo();
        if (activityInfo != null) {
            List<String> paramList = new ArrayList<>();
            long recycleTime = activityInfo.getEndTime() * 1000L + gapTime;
            paramList.add(String.valueOf(config.getLIGHTMARKET_ENERGY_ITEM_ID()));
            paramList.add(String.valueOf(config.getEXCHANGE_SCORE_ITEM_ID()));
            paramList.add("1");
            paramList.add(activityInfo.getActivityName());
            ActivityItemRecycleMgr.addRecycleItemData(config.getLIGHTMARKET_ENERGY_ITEM_ID(), activityType, 0, recycleTime, paramList);
            // 回收武力人偶
            ActivityItemRecycleMgr.addRecycleItemData(config.getLIGHTMARKET_DOY_WULI_ITEM_ID(), activityType, 1, recycleTime, new ArrayList<>());
        }
    }

    @Override
    public boolean isActivityRunning() {
        ActivityInfo activityInfo = JieShiMgr.getConfig().getActivityInfo();
        return ActivityMgr.activityInTime(activityInfo);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.JieShi.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 0) {
            item2Score(userId, data);
        } else if (data.getRecycleType() == 1) {
            int itemId = data.getItemId();
            UserBagItem userBagItem = getUserBagItem(userId, itemId);
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }


}
